package cn.sc.summer.constant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 异常类型枚举类
 *
 * @author a-xin
 * @date 2023/1/19 2:14 PM
 */
@Getter
@AllArgsConstructor
@SuppressWarnings("all")
public enum ExceptionTypeEnum {

    LOGIN_TOKEN_EXPIRED(401, "未授权"),
    LOGIN_EXPIRE(403, "登录过期"),

    PAGE_NOT_FIND(404, "不存在对应的资源"),

    USER_NOT_EXIST(501, "用户不存在"),
    USER_PASSWORD_ERROR(502, "用户密码错误"),

    NOT_FIND_GRIL_FRIEND_EXCEPTION(99901, "Girlfriend not found exception!"),
    NOT_FIND_MONEY_EXCEPTION(99902, "Money not found exception!"),
    HAVE_NO_ACCESS(99903, "Sorry, you don't have access to this api！");

    private String message;
    private Integer code;

    ExceptionTypeEnum(int code, String message) {
        this.message = message;
        this.code = code;
    }

    public static String getMessage(Integer code) {
        for (ExceptionTypeEnum c : ExceptionTypeEnum.values()) {
            if (c.getCode() == code) {
                return c.message;
            }
        }
        return null;
    }

    public String getMessage() {
        return message;
    }

    public int getCode() {
        return code;
    }

}
